package com.quectel.mobile.controller.partybuilding;

import cn.hutool.core.lang.func.LambdaUtil;
import com.quectel.constant.global.SystemConstants;
import com.quectel.core.module.partybuildingbanner.dto.PartyBuildingBannerDto;
import com.quectel.core.module.partybuildingbanner.service.PartyBuildingBannerService;
import com.quectel.mobile.controller.BaseController;
import com.quectel.util.common.Page;
import com.quectel.util.common.Request;
import com.quectel.util.common.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 在这里编写说明
 *
 * @author: bob
 * @email: bob.yu@quectel.com
 * @date: 2023-06-13 9:02:00
 */
@RestController
@RequestMapping("partyBuildingBanner")
@Tag(name = "PartyBuildingBannerController", description = "智慧党建Banner资源相关api")
public class PartyBuildingBannerController extends BaseController {

    @DubboReference
    private PartyBuildingBannerService partyBuildingBannerService;

    @GetMapping("list")
    @Operation(summary = "移动端banner资源的分页查询列表")
    public Response<Page<PartyBuildingBannerDto>> list() {
        Map<String, Object> params = new HashMap<String, Object>();
        Request request = Request.configParams(params);

        request.getParams().put(LambdaUtil.getFieldName(PartyBuildingBannerDto::getStatus), SystemConstants.YES);

        int totalCount = partyBuildingBannerService.queryTotal(request.getParams());
        List<PartyBuildingBannerDto> list = null;
        if (totalCount > 0) {
            list = partyBuildingBannerService.queryList(params);

        } else {
            list = new ArrayList<>();
        }
        Page<PartyBuildingBannerDto> page = new Page<>(request.getPageNo(), request.getPageSize(), totalCount, list);
        return Response.<Page<PartyBuildingBannerDto>>ok().wrap(page);
    }

}
